package shili;

import org.apache.log4j.Logger;

public class test {
    public static void main(String[] args) {
        Logger logger = Logger.getLogger(IntermediaryImpl.class);

        // 示例3(2)
        NewsDao dao = SimpleDaoFactory.getInstance();
        NewsServiceImpl service = new NewsServiceImpl();
        service.setDao(dao);

        // 示例3(3)
        NewsDao dao1 = SimpleDaoFactory.getInstance();
        NewsServiceImpl service1 = new NewsServiceImpl();
        service1.setDao(dao1);

        // 示例5(3)
        AbstractFactory factory = new MySqlDaoFactory();    // 改变具体工厂可创建不同产品
        NewsDao dao2 = factory.getInstance();
        NewsServiceImpl service2 = new NewsServiceImpl();
        service2.setDao(dao2);

        // 示例6(4)
        Buyer buyer = new IntermediaryImpl(new RealBuyer());
        String result = buyer.havealook();
        logger.debug(result);

        // 示例7(2)
        RealBuyer buyer1 = new IntermediarySubclass();
        String result1 = buyer1.havealook();
        logger.debug(result1);

        // 示例8(4)
        Buyer buyer2 = IntermediaryJdkProxyFactory.create(new RealBuyer());
        String result2 = buyer2.havealook();
        logger.debug(result2);

        // 实例9(3)
        RealBuyer buyer3 = IntermediaryCglibProxyFactory.create(RealBuyer.class);
        String result3 = buyer3.havealook();
        logger.debug(result3);
    }
}
